
default_platform :ios

platform :ios do
  desc 'Lane compilations'
  #发邮件
  lane :cx_send_email do |options|
      stmp_server = options[:stmp_server]
      user_name = options[:user_name]
      password = options[:password]
      recipients = options[:recipients]
      subject = options[:subject]
      message_body = options[:message_body]
      send_msg(
               stmp_server: stmp_server,
               user_name:user_name,
               password:password,
               recipients: recipients,
               subject:subject,
               message_body:message_body
               )
  end


  #删除远程标签 本地标签
  lane :cx_remove_tag do |options|
      tagName = options[:tag]
      remove_tag(
               tag:tagName
               )
  end


  #gitHub版本发布
  lane :cx_gitHubLib do |options|
      # 打标签需要和podspec的版本对应
      tagName = options[:tag]
      # 被上传的目标podspec文件
      targetName = options[:target]
      # 本次更新的内容
      msgName = options[:msg]
      
      cocoapods(
      clean: true,
      podfile: "./Example/Podfile"
      )

      git_add(path: ".")

      git_commit(path: ".", message: "#{msgName}")

      push_to_git_remote

      if git_tag_exists(tag: tagName)
          UI.message("发现tag:#{tagName} 之前有tag,删除原来的标签🚀")
          remove_tag(tag:tagName)
      end

      add_git_tag(
      tag: tagName
      )

      push_git_tags

      # pod_lib_lint(allow_warnings: true,sources: ['https://github.com/CocoaPods/Specs.git'])

      pod_lib_lint(allow_warnings: true,sources: ['https://cdn.cocoapods.org/'])

      pod_push(path: "#{targetName}.podspec",allow_warnings: true,use_libraries:true,verbose:true)

  end  

    #私有库版本发布
  lane :cx_lib do |options|
      # 打标签需要和podspec的版本对应
      tagName = options[:tag]
      # 被上传的目标podspec文件
      targetName = options[:target]
      # 本次更新的内容
      msgName = options[:msg]
      
      cocoapods(
      clean: true,
      podfile: "./Example/Podfile"
      )

      git_add(path: ".")

      git_commit(path: ".", message: "#{msgName}")

      push_to_git_remote

      if git_tag_exists(tag: tagName)
          UI.message("发现tag:#{tagName} 之前有tag,删除原来的标签🚀")
          remove_tag(tag:tagName)
      end

      add_git_tag(
      tag: tagName
      )

      push_git_tags

    #   pod_lib_lint(allow_warnings: true,sources: ['https://gitee.com/caixiang19901217/OpenSpecs.git','https://cdn.cocoapods.org/'],use_libraries:true)

    #   pod_lib_lint(podspec:"./Example/#{targetName}.podspec", allow_warnings: true,sources: ['https://gitee.com/caixiang19901217/OpenSpecs.git','https://cdn.cocoapods.org/'],use_libraries:true)

    #   pod_push(path: "#{targetName}.podspec", repo: "OpenSpecs", allow_warnings: true,sources: ['https://gitee.com/caixiang19901217/OpenSpecs.git','https://cdn.cocoapods.org/'],use_libraries:true)

#        pod_push(path: "#{targetName}.podspec", repo: "OpenSpecs", allow_warnings: true,sources: ['https://gitee.com/caixiang19901217/OpenSpecs.git','https://cdn.cocoapods.org/'],use_libraries:true)

pod_push(path: "#{targetName}.podspec", repo: "OpenGitSpecs", allow_warnings: true,sources: ['git@gitlab.open.com.cn:tongxueBussiness/Face2face/iOS/openpubliclib.git','https://cdn.cocoapods.org/'],use_libraries:true)

      # pod_lib_lint(allow_warnings: true,sources: ['https://gitee.com/caixiang19901217/OpenSpecs.git','https://github.com/CocoaPods/Specs.git'],use_libraries:true)

      # pod_push(path: "#{targetName}.podspec", repo: "OpenSpecs", allow_warnings: true,sources: ['https://gitee.com/caixiang19901217/OpenSpecs.git','https://github.com/CocoaPods/Specs.git'],use_libraries:true)

  end  


      #主动拉去更新
  lane :pod_repo  do |options|
       repoName = options[:repo]
      update_openlib(repo:repoName)
  end  
  

  error do |lane, exception|
    UI.message(exception.message)
  end
  
end
